<template>
	<view class="bankcard-list">
		<view class="bankcard-list-cell" v-for="item in dataList" :key="item.id">
			<image :src="item.bankIcon" mode="aspectFit"></image>
			<view class="bankcard-list-cell-container">
				<text>{{item.bankName}}（{{item.isPublic == '0' ? '对公' : '对私'}}）</text>
				<text>储蓄卡</text>
				<text>{{formatBankNo(item)}}</text>
			</view>
			<text class="bankcard-list-cell-change-text" @tap="changeBankCard(item)">变更</text>
		</view>
		<view class="bankcard-list-bind-box" @tap="bindCompanyBankCard" v-if="isCanBindPublicBankCard()">
			<view class="bankcard-list-bind-top">
				<image src="/static/wallet/settle_bind_company_icon.png" mode="aspectFit"></image>
				<text>企业对公</text>
				<text style="color: #FF0203;font-size: 30rpx; margin-left: auto;">立即绑定</text>
			</view>
			<view class="bankcard-list-bind-tip">仅支持绑定认证时对应的企业对公银行帐户</view>
		</view>
	</view>
</template>

<script setup>
	import { onShow } from '@dcloudio/uni-app'
	import { ref } from 'vue'
	import { getSettleList } from '@/common/api/api.js'
	import { useUserStore,useFormStore } from '@/common/stores'
	const userStore = useUserStore()
	const formStore = useFormStore()
	const dataList = ref([])
	// 绑定对公结算卡
	const bindCompanyBankCard = ()=>{
		uni.navigateTo({
			url:'/pages/wallet/bankcard-list/bankcard-public/bankcard-public'
		})
	}
	// 变更结算卡
	const changeBankCard = (item)=>{
		formStore.$reset()
		const dataStr = decodeURIComponent(JSON.stringify(item))
		if(item.isPublic == '0'){
			uni.navigateTo({
				url:`/pages/wallet/bankcard-list/bankcard-public/bankcard-public?data=${dataStr}`
			})
		}
		else{
			uni.navigateTo({
				url:`/pages/my/auth/bankcard/bankcard?data=${dataStr}`
			})
		}
		
	}
	// 格式化显示银行卡
	const formatBankNo = (item)=>{
		return uni.$utils.formatBankCardNo(item.cardNo)
	}
	// 获取我的结算卡列表
	const getMySettleListData = async ()=>{
		const res = await getSettleList()
		dataList.value = res.result
	}
	// 是否可以绑定对公结算卡
	const isCanBindPublicBankCard = ()=>{
		const res = dataList.value.filter(item=>item.isPublic == '0')
		if(userStore.user.agentType == '02' && res.length == 0){
			return true
		}
		return false
	}
	onShow(()=>{
		getMySettleListData()
	})
	
</script>

<style lang="scss" scoped>
.bankcard-list{
	padding: 30rpx;
	.bankcard-list-cell{
		background-color: #fff;
		border-radius: 16rpx;
		padding: 30rpx;
		display: flex;
		margin-bottom: 30rpx;
		image{
			width: 64rpx;
			height: 64rpx;
			flex-shrink: 0;
			margin-top: -10rpx;
		}
		.bankcard-list-cell-container{
			display: flex;
			flex-direction: column;
			flex: 1;
			margin-left: 20rpx;
			font-size: 30rpx;
			font-weight: 500;
			text:nth-child(2){
				margin: 16rpx 0;
				font-size: 26rpx;
				color: $xh-color-9;
				font-weight: 400;
			}
		}
		.bankcard-list-cell-change-text{
			color: $xh-theme-color;
			font-size: 30rpx;
			flex-shrink: 0;
		}
		
	}
	.bankcard-list-bind-box{
		padding: 30rpx;
		background-color: #fff;
		border-radius: 16rpx;
		.bankcard-list-bind-top{
			display: flex;
			align-items: center;
			image{
				width: 64rpx;
				height: 64rpx;
				flex-shrink: 0;
			}
			text:nth-of-type(1){
				margin-left: 20rpx;
				font-size: 30rpx;
				font-weight: 500;
			}
		}
		.bankcard-list-bind-tip{
			color: $xh-color-9;
			margin-top: 30rpx;
		}
	}
}
</style>
